#include <bits/stdc++.h>
using namespace std;

const int N = 1e5+5;

int n, m;
vector<int> G[N];

namespace tarjan {
    int low[N], dfn[N], clk, B, bl[N];
    vector<int> bcc[N];

    bool discard[N];

    void init(int n) {
        B = clk = 0;
        memset(dfn, 0, sizeof(int) * (n+1));
        memset(discard, 0, sizeof(bool) * (n+1));
        for (int i=0; i<n; ++i) bcc[i].clear();
    }

    void tarjan(int u) {
        static int st[N], p;
        static bool in[N];
        dfn[u] = low[u] = ++clk;
        st[p++] = u; in[u] = true;
        for (int &v : G[u]) {
            if (!dfn[v]) {
                tarjan(v);
                low[u] = min(low[u], low[v]);
            } else if (in[v]) low[u] = min(low[u], dfn[v]);
            else discard[bl[v]] = 1;
        }
        if (dfn[u] == low[u]) {
            while (1) {
                int x = st[--p]; in[x] = false;
                bl[x] = B; bcc[B].push_back(x);
                if (x == u) break;
            }
            if (p > 0) discard[B] = 1;
            ++ B;
        }
    }

    vector<int> foo() {
        vector<int> ans;
        for (int i=0; i<B; ++i) {
            if (!discard[i]) {
                int minx = bcc[i][0];
                for (int x : bcc[i])
                    minx = min(minx, x);
                ans.push_back(minx);
            }
        }
        return ans;
    }

    void go(int n) {
        init(n);
        for (int i=0; i<n; ++i) {
            if (!dfn[i]) tarjan(i);
        }
    }
}

int main(int argc, char const *argv[])
{
    scanf("%d%d", &n, &m);
    for (int i=0; i<m; ++i) {
        int u, v;
        scanf("%d%d", &u, &v);
        --u; --v;
        G[u].push_back(v);
    }

    tarjan::go(n);
    vector<int> ans = tarjan::foo();
    printf("%d\n", (int)ans.size());

    for (int i=0; i<ans.size(); ++i)
        printf("%d%c", ans[i]+1, i==ans.size()-1? '\n':' ');
    return 0;
}
